package com.yunshang.shoppingmall.shopping.productApi.controller;


import com.yunshang.shoppingmall.entity.ProductComment;

import com.yunshang.shoppingmall.service.ProductCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

/**
 * 商品评论
 */
@Controller
@RequestMapping("/wap")
public class ProductCommentController {

    @Autowired
    ProductCommentService productCommentService;
    /*打开增加评论页面*/
    @RequestMapping(value = "/openComment")
    public ModelAndView openComment(HttpServletRequest request){
        Map<String ,Object> map=new HashMap<>();
        String userId=request.getParameter("userId");
        userId="10055";
        String guigeId=request.getParameter("guigeId");
        ModelAndView modelAndView=new ModelAndView("shoppingApi/product/comment");
        map.put("userId",userId);
        map.put("guigeId",guigeId);
        modelAndView.addObject("map",map);
        return modelAndView;
    }
    @ResponseBody
    @RequestMapping(value = "/addProductComment",method = RequestMethod.POST)
    public Map<String,Object> addProductComment(HttpServletRequest request){
        Map<String,Object> map=new HashMap<>();
        int userId=0;
       String userIds= request.getParameter("userId");
        String content=request.getParameter("content");
        String niMingSign=request.getParameter("niMingSign");
       if(userIds!=null&&userIds!=""){
            userId=Integer.parseInt(userIds);
       }

        ProductComment productComment=new ProductComment();
        productComment.setUserId(userId);
        productComment.setcContent(content);

        productComment.setNiMingSign(niMingSign);

        Timestamp timestamp=new Timestamp( System.currentTimeMillis());
        productComment.setcTime(timestamp);
        int row= productCommentService.insert(productComment);
      if(row>0){
          map.put("msg",'1');
      }else{
          map.put("msg",'0');
      }
      return map;
    }


}
